<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
          "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>QUnit for RSAKey signing add-on 'rsa-sign.js of RSAPSS signature'</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="qunit.js"></script>
<link rel="stylesheet" href="qunit.css" type="text/css" media="screen" />

<script src="../ext/cj/cryptojs-312-core-fix.js"></script>
<script src="../ext/cj/x64-core.js"></script>
<script src="../ext/cj/cipher-core_min.js"></script>
<script src="../ext/cj/aes_min.js"></script>
<script src="../ext/cj/tripledes_min.js"></script>
<script src="../ext/cj/enc-base64_min.js"></script>
<script src="../ext/cj/md5_min.js"></script>
<script src="../ext/cj/sha1_min.js"></script>
<script src="../ext/cj/sha256_min.js"></script>
<script src="../ext/cj/sha224_min.js"></script>
<script src="../ext/cj/sha512_min.js"></script>
<script src="../ext/cj/sha384_min.js"></script>
<script src="../ext/cj/ripemd160_min.js"></script>
<script src="../ext/cj/hmac_min.js"></script>
<script src="../ext/cj/pbkdf2_min.js"></script>

<script src="../ext/yahoo.js"></script>
<script src="../ext/jsbn.js"></script>
<script src="../ext/jsbn2.js"></script>
<script src="../ext/prng4.js"></script>
<script src="../ext/rng.js"></script>
<script src="../ext/rsa.js"></script>
<script src="../ext/rsa2.js"></script>
<script src="../ext/base64.js"></script>

<script src="../src/rsapem-1.1.js"></script>
<script src="../src/rsasign-1.2.js"></script>
<script src="../src/asn1hex-1.1.js"></script>
<script src="../src/crypto-1.1.js"></script>
<script src="../src/keyutil-1.0.js"></script>
<script src="../src/base64x-1.1.js"></script>

<script src="../ext/ec.js"></script>
<script src="../ext/ec-patch.js"></script>
<script src="../src/ecdsa-modified-1.0.js"></script>

<script>
$(document).ready(function(){

// _work_pss/kp1.prv.pem
var sKp1PrvPEM = "" + 
"-----BEGIN RSA PRIVATE KEY-----\n" +
"MIIEpQIBA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xOIG2Jhr3F+2oU7o7zr0vn3lrbK\n" +
"YK8Ppo+9mKTf5r+l+nwCWm14hNpaPZM5M8UKCfPWSsMH01OZ5x/4/KdWkteyyUwY\n" +
"twIDAQAB\n" +
"-----END PUBLIC KEY-----\n";

// _work_pss/kp1.sig.aaa.-1.1
var sKp1SigAAA1 = "4c392f5428c5d76a1dd0eb665954bf8600024d5759506f223f77cbbf0fded92b0d1679658caaf7870ea82fd24b55008b19dd78fdf76f6cd857fb96d665f07f8cf08c84251d98e8719021c46e37e65c7389cc443292ff0111d6bd88c8a47b10a6faed5c95159c5a3642064064ca0b3d2c560222afa9f0c184096584893bd3d6e888ee6d3fe56fa772ed9bda7663520ebc66f33505cd0622138b26f1790dee99635f9094bcb424b31568c4d0a9475118d0a0a7a80359c3022fcf75069e7213c47d79e5542b84fca9123161c5fa9c757b019bac03f4c62839c3bd31923a7d46ae47299ab0c51e0124ee37c5d52afff0be2c37ad6d8196ba54bc28fb80cc979ab05f";

// _work_pss/kp1.sig.aaa.-1.2
var sKp1SigAAA2 = "18b6b70deeb89dca5a8542feaaa08547de49d957afd98b6a2d3a083db340d2b3d2277c475a401275c02c38590529c609167fb953c397b4cd31a0cc5048d0b9403156173e7bba668033267a4fbfd355bff6570defd1c6bc192c4a4e244fc8045093cb0519e409ea1399e9c0367a9136a3423a804f625af95a0715c08d35ffab217581da2cc76fbc1d0075e07f7dec9a9400ac3ef7fea28e876b7d0ffe13441bed228e4f0c72d90361485d1b322c285ce11f2555a52936ed405bb546f58280cb41071e7b7a656009b68d925fdba0c5a77fc6991cee117a8c4511fc0d55930262ba7a2e3cff1ea01aff8c4e763f5bbf31a6d9e6a508cc6bb46b17b7671510a2fb23";

// _work_pss/kp1.sig.aaa.-2.3
var sKp1SigAAA3 = "03fe7741e637140571e468ae84e76583ce040f7179fae7f378225f9eace7e4599c95f0393003be84c7d6fc263bacfa97ac07784482335e64a4c4d5fbc58697a3d0fa005230508a9f40ea8d5f6791694e07627ea47c0b4a3f6b9055e2add8b7eab99052ee40f1bcde65e2b1237f63afafcc9b69d86993ce7e4a5827df3462d79b55647da5781a6dda37b6763a2eca986ef5a7d71ed341a7cc99ce9b22b7b3e06ea0d1020914f8742a18453c410b91753b8ad2e50c6d2b5aa8affd30f61b4d4eb396a0fc0393e9dba5eb8ec78e543ecc2b4739d09a8b6879263b32a0c5f39c1eba40ea7a1991c4b03926245cf4c3d9b5076831f9aebd34745432e6e15fceb80276";

// _work_pss/kp1.sig.aaa.-2.4
var sKp1SigAAA4 = "455cda85ae69b91d29b82c27ec3cd8d335d443153558fd6a28599b5da5957aa5e96fe5c93e0700ab2efaaef8a1665e3eee68fb4ecd8a1f51c5434fa375464c6b4c4eb9184bc6ec8d2dbb5d75982ba7b6b5ca79041baadaa29f4329f47d4fbecafcd14c2794e32ccd4340fb7efec9c57bb0a5a6dbba331fdfa82f51fbe0bf47ff97892902f53b4906cc9ff438dbacf4c834251f2b8f95cdc066097d5ea4ffac3ff4c5f19c72863850fa1be5f48c94100eb20e4cee4265d21629413250a46e1ee14a4f4a576fbc9bb76ec0625f0941d7aa903fe392cf5fbb5ceaf3769dd432dd73c67df61f04471b1b79bab178c7db70ccecaa8900618874f314484b20e367517b";

// _work_pss/PSS1.out.1
var sKp1SigAAA5 = "0bc25d05bc518cd752e5fe956382dbced768cd7d2f3751e96ca948d6b78c31fb5b36b4469030ef3f55b478f11bacbf431e74da3b276873cbbb63a8c38923349cf9ecfd4f3652afa3057f414a3bd263b4f85cd2f97b2554c807a65299b3c3893e9d118dd657801ad3de6fc6fdd6dabe382d3f24e2b9ac3538e8370c7f3ec8fb334a5ea7b33308a7e4b70c8c46b4f8589a2c5b943a684db6e623c567b92e19f00873fdfc16aee449e6cb5b4250ba817dc21188027a87c3255f6dec210fe4157b7e8c567c36e932687853476ec2191006e1dc1d916e983139577cd4da3b1d38555513ac6551c135ef6b2e7316e0d8b5c0ab2bc7e79f7f35584a33851e05230034c1";

//=========================================================================
module("Verifier Test");

test("Signature(SHA1withRSAandMGF1) kp1.sig.aaa.-1.1 verify test", function() {
  var pubKey = KEYUTIL.getKey(sKp1PubPEM);
  var s1 = new KJUR.crypto.Signature({"alg": "SHA1withRSAandMGF1"});
  s1.initVerifyByPublicKey(pubKey);
  s1.updateString('aaa');
  var result = s1.verify(sKp1SigAAA1);
  equal(result, true, 'kp1.sig');
});

test("Signature(SHA1withRSAandMGF1) kp1.sig.aaa.-1.2 verify test", function() {
  var pubKey = KEYUTIL.getKey(sKp1PubPEM);
  var s1 = new KJUR.crypto.Signature({"alg": "SHA1withRSAandMGF1"});
  s1.initVerifyByPublicKey(pubKey);
  s1.updateString('aaa');
  var result = s1.verify(sKp1SigAAA2);
  equal(result, true, 'kp1.sig');
});

test("Signature(SHA1withRSAandMGF1) kp1.sig.aaa.-2.3 verify test", function() {
  var pubKey = KEYUTIL.getKey(sKp1PubPEM);
  var s1 = new KJUR.crypto.Signature({"alg": "SHA1withRSAandMGF1",
                                      "psssaltlen": -2});
  s1.initVerifyByPublicKey(pubKey);
  s1.updateString('aaa');
  var result = s1.verify(sKp1SigAAA3);
  equal(result, true, 'kp1.sig');
});

test("Signature(SHA1withRSAandMGF1) kp1.sig.aaa.-2.4 verify test", function() {
  var pubKey = KEYUTIL.getKey(sKp1PubPEM);
  var s1 = new KJUR.crypto.Signature({"alg": "SHA1withRSAandMGF1",
                                      "psssaltlen": -2});
  s1.initVerifyByPublicKey(pubKey);
  s1.updateString('aaa');
  var result = s1.verify(sKp1SigAAA4);
  equal(result, true, 'kp1.sig');
});

test("Signature(SHA1withRSAandMGF1) PSS1.out.1 verify test", function() {
  var pubKey = KEYUTIL.getKey(sKp1PubPEM);
  var s1 = new KJUR.crypto.Signature({"alg": "SHA1withRSAandMGF1"});
  s1.initVerifyByPublicKey(pubKey);
  s1.updateString('aaa');
  var result = s1.verify(sKp1SigAAA5);
  equal(result, true, 'kp1.sig');
});

test("Signature(SHA1withRSAandMGF1) kp1 sign and verify", function() {
  var prvKey = new RSAKey();
  prvKey.readPrivateKeyFromPEMString(sKp1PrvPEM);
  var s1 = new KJUR.crypto.Signature({"alg": "SHA1withRSAandMGF1"});
  s1.initSign(prvKey);
  s1.updateString('aaa');
  var hSigValue = s1.sign();

  var pubKey = KEYUTIL.getKey(sKp1PubPEM);
  var s2 = new KJUR.crypto.Signature({"alg": "SHA1withRSAandMGF1"});
  s2.initVerifyByPublicKey(pubKey);
  s2.updateString('aaa');
  var result = s2.verify(hSigValue);

  equal(result, true, 'kp1.sig');
});

test("Signature(SHA256withRSAandMGF1) kp1 sign and verify", function() {
  var prvKey = new RSAKey();
  prvKey.readPrivateKeyFromPEMString(sKp1PrvPEM);
  var s1 = new KJUR.crypto.Signature({"alg": "SHA256withRSAandMGF1"});
  s1.initSign(prvKey);
  s1.updateString('aaa');
  var hSigValue = s1.sign();

  var pubKey = KEYUTIL.getKey(sKp1PubPEM);
  var s2 = new KJUR.crypto.Signature({"alg": "SHA256withRSAandMGF1"});
  s2.initVerifyByPublicKey(pubKey);
  s2.updateString('aaa');
  var result = s2.verify(hSigValue);

  equal(result, true, 'kp1.sig');
});

});
</script>
  
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture">test markup</div>
</body>
</html>



